<%@page import="java.text.SimpleDateFormat"%>
<%@page import="classes.Conexao"%>
<%@page import="java.util.Date"%>
<%@page import="classes.Conexao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" import="java.sql.*"%>
<%
    Integer parcial = 0;
    Integer percent = 0;
    Integer total = 0;
    String data = request.getParameter("ano") + "-" + request.getParameter("mes") + "-" + request.getParameter("dia");

    String str = "";
    
    long cd_usuario = Long.parseLong(session.getAttribute("cd_usuario").toString());
    
    try {
        String SQL = "(SELECT SUM(distinct qt_porcao) "
                + "FROM \"Operacoes\".\"USUARIO_REFEICAO\" "
                + "WHERE dt_usuario_refeicao = '" + data + "' "
                + "AND cd_usuario = " + cd_usuario + ") ";
        for (Object[] reg : Conexao.getQuery(SQL)) {
            if (reg[0]!=null){            
                percent = (int) Math.round(((Double.parseDouble(reg[0].toString()) * 100) / 120));
                if (percent > 100) {
                    percent = 100;
                }
            } else {
               percent = 0;
            }
            total += (percent*2);
            str = str + percent + ":";
        }
        
        SQL = "SELECT SUM(distinct qt_hidratacao) "
                + "FROM \"Operacoes\".\"HIDRATACAO\" "
                + "WHERE date(dt_hidratacao) = '" + data + "' "
                + "AND cd_usuario = " + cd_usuario + "; ";
        for (Object[] reg : Conexao.getQuery(SQL)) {
            if (reg[0]!=null){
                percent = (int) Math.round(((Double.parseDouble(reg[0].toString()) * 100) / 2000));
                if (percent > 100) {
                    percent = 100;
                }
            } else {
               percent = 0;
            }
            str = str + percent + ":";
            total += percent;
        }
        
        SQL = "SELECT SUM(distinct qt_atividade_fisica) "
                + "FROM \"Operacoes\".\"ATIVIDADE_FISICA\" "
                + "WHERE dt_atividade_fisica = '" + data + "' "
                + "AND cd_usuario = " + cd_usuario + "; ";
        for (Object[] reg : Conexao.getQuery(SQL)) {
            if (reg[0]!=null){               
                percent = (int) Math.round(((Double.parseDouble(reg[0].toString()) * 100) / 30));
                if (percent > 100) {
                    percent = 100;
                }
            } else {
               percent = 0;
            }
            total += percent;
            total = (int) Math.round(total/4); //3
            str = str + percent + ":";
            str = str + total + ":";
        }
        str = str.substring(0, str.length() - 1);
        System.out.println(str);
        out.println(str);
    } catch (Exception ex1) {
        ex1.printStackTrace();
    }
%>